﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace EnterpriseFund.DAL
{
    public class OperateLog
    {
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.OperateLog model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_OperateLog(");
            strSql.Append("FEntityNo,FLogID,Fdate,Fnote,FfunctName,Fhost,FFunctNo,Fcip,FMethod,FUserAgent,FReferer,FsessionID,fbrowser,fos,fvisitfilename,fparam)");
            strSql.Append(" values (");
            strSql.Append("@FEntityNo,@FLogID,@Fdate,@Fnote,@FfunctName,@Fhost,@FFunctNo,@Fcip,@FMethod,@FUserAgent,@FReferer,@FsessionID,@fbrowser,@fos,@fvisitfilename,@fparam)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FLogID", SqlDbType.NVarChar,30),
					new SqlParameter("@Fdate", SqlDbType.DateTime),
					new SqlParameter("@Fnote", SqlDbType.VarChar,200),
					new SqlParameter("@FfunctName", SqlDbType.VarChar,40),
					new SqlParameter("@Fhost", SqlDbType.VarChar,80),
					new SqlParameter("@FFunctNo", SqlDbType.NVarChar,80),
					new SqlParameter("@Fcip", SqlDbType.VarChar,15),
					new SqlParameter("@FMethod", SqlDbType.VarChar,80),
					new SqlParameter("@FUserAgent", SqlDbType.VarChar,200),
					new SqlParameter("@FReferer", SqlDbType.VarChar,255),
					new SqlParameter("@FsessionID", SqlDbType.VarChar,64),
					new SqlParameter("@fbrowser", SqlDbType.VarChar,255),
					new SqlParameter("@fos", SqlDbType.VarChar,255),
					new SqlParameter("@fvisitfilename", SqlDbType.VarChar,255),
					new SqlParameter("@fparam", SqlDbType.VarChar,255)};
            parameters[0].Value = model.FEntityNo;
            parameters[1].Value = model.FLogID;
            parameters[2].Value = model.Fdate;
            parameters[3].Value = model.Fnote;
            parameters[4].Value = model.FfunctName;
            parameters[5].Value = model.Fhost;
            parameters[6].Value = model.FFunctNo;
            parameters[7].Value = model.Fcip;
            parameters[8].Value = model.FMethod;
            parameters[9].Value = model.FUserAgent;
            parameters[10].Value = model.FReferer;
            parameters[11].Value = model.FsessionID;
            parameters[12].Value = model.fbrowser;
            parameters[13].Value = model.fos;
            parameters[14].Value = model.fvisitfilename;
            parameters[15].Value = model.fparam;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 1;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
    }
}
